package com.lc.admin.web;

import com.lc.admin.base.PageResponse;
import com.lc.admin.base.ResponseResult;
import com.lc.admin.bean.Reservation;
import com.lc.admin.constants.PagerConstants;
import com.lc.admin.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//@Api(tags="预约管理")
@RestController
@RequestMapping("/reservation")
public class ReservationWeb {

    @Autowired
    ReservationService reservationService;

//    @ApiOperation("后端分页条件查询")
    @GetMapping("/list")
    public ResponseResult<PageResponse<Reservation>> listByPage(
            @RequestParam(defaultValue = PagerConstants.PAGE_STR) Integer page,
            @RequestParam(defaultValue = PagerConstants.PAGE_SIZE_STR) Integer pageSize,
            Reservation reservation) {
        PageResponse<Reservation> pageRe = reservationService.listByPage(page, pageSize, reservation);
        return ResponseResult.success(pageRe);
    }


    @PostMapping("/save")
    public ResponseResult save(@RequestBody Reservation reservation) {
        try {
            reservationService.save(reservation);
        } catch (Exception e) {
            return ResponseResult.error(e.getMessage());
        }
        return ResponseResult.success();
    }

    @PutMapping("/edit")
    public ResponseResult edit(@RequestBody Reservation reservation) {
        int count = 0;
        try {
            count = reservationService.update(reservation);
        } catch (Exception e) {
            return ResponseResult.error(e.getMessage());
        }
        if(count==1) {
            return ResponseResult.success();
        }
        return ResponseResult.error();
    }
}
